var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var db = require('../database/db.js')
const cate = require('../cate/cate.js'); // 之前的分类
const teacher = require('../bin/models/teacherModels');
const paper = require('../bin/models/paperModels');
const questionControl = require('../bin/control/questionControl')



/* GET home page. */
router.get('/', function(req, res, next) {  //登录页
  res.render('login');
});

router.get('/Qindex', function(req, res, next) {  //登录页
  res.render('Qindex');
});

router.get('/Quser', function(req, res, next) {  //登录页
  res.render('Quser');
});

router.get('/Qlist', function (req, res, next) {  //评教记录
  questionControl.findAllQuestion((dbs) => {
    paper.find({ userId: req.query.userId, teacherId: req.query.teacherId }, (dbs2) => {
      res.render('Qlist',{data_h:dbs,data_h2:dbs2});
    })
  })

});

router.get('/Qregister', function(req, res, next) {  //登录页
  res.render('Qregister');
});

router.get('/QselectTeacher', function (req, res, next) {  //选择教师的页面
  teacher.find_num({}, 10, 0, function (dbs) {
    console.log(dbs)
    paper.find({ userId: req.query.userId }, (dbs2)=>{
      for (let i in dbs) {
        dbs[i].isPingjiao = "否"
        for (let j in dbs2) {
          console.log(dbs[i]._id.toString(),dbs2[j].teacherId)
          if (dbs[i]._id.toString() === dbs2[j].teacherId) {
            dbs[i].isPingjiao = "是"
          }
        }
      }
      res.render('selectTeacher',{data:JSON.stringify(dbs),data_h:dbs});
    })
  });
});


module.exports = router;
